<template>
	<div class="ly-root page-add">
		<input class="chapter-title" type="textarea" v-model="chapter.title" />
		<textarea class="chapter-text" type="textarea" v-model="chapter.text" />
		<el-select class="chapter-text" v-model="chapter.type" placeholder="请选择节点类型">
			<el-option
			v-for="item in typeOptions"
			:key="item.value"
			:label="item.label"
			:value="item.value">
			</el-option>
		</el-select>
		<vue-markdown :source="mdData.source"></vue-markdown>
		<el-button  @click="save">保存</el-button>
	</div>
</template>

<script>
import * as web3CTR from '@/utils/web3-ctr'
import _ from 'lodash'
import VueMarkdown from 'vue-markdown'

export default {
	name: 'story-list',
	components: {
		VueMarkdown
	},
	data(){
		return {
			typeOptions:[
				{
					value: 0,
					label: '章'
				},
				{
					value: 1,
					label: '节'
				},
				{
					value: 2,
					label: '正文'
				}
			],
			mdData:{ //markdown 配置
			},
			chapter:{
				type:'',
				text:'',
				level: 0
			},
			prev_addr: '',
			head_addr: ''
		}
	},
	created(){
		this.prev_addr = this.$route.params.prev
		this.head_addr = this.$route.query.headaddr
		this.chapter.level = this.$route.query.level
	},
	mounted(){
	},
	methods:{
		save(){
			console.log("HHHHHHHH", this.chapter)
			let owner = "0x4Dff49A45E35C2970A549Ba56D90cEb64E6B37D2"
			web3CTR.addChapter({
				prev: this.prev_addr,
				text:this.chapter.text,
				owner,
				h_addr:this.head_addr,
				level: this.chapter.level,
				type: this.chapter.type
			}).then(()=>{
				this.$router.back()
			})
		}
	}
}
</script>
<style lang="stylus" scoped>
.page-add{
	padding: 20px;
	.chapter-title{
		width:100%;
		box-sizing border-box
		margin-bottom 15px
	}
	.chapter-text{
		width:100%;
		box-sizing border-box
		height 100px
		margin-bottom 15px
	}
}
</style>
